import { defineConfig, UserConfig, ConfigEnv, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
  const env = loadEnv(mode, process.cwd());

  return {
    base:"/vue3.2-admin",
    plugins: [
      vue(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(__dirname, "src/icons/svg")],
        symbolId: "icon-[name]",
      }),
    ],
    css: {
      // CSS 预处理器
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: `
            @use "@/styles/variables.scss" as *;
          `,
        },
      },
    },
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src")
      },
    },
    // 代理
    server: {
      host: "0.0.0.0", // 允许IP访问
      port: Number(env.VITE_APP_PORT),  // 应用端口
      // open: true, // 运行是否自动打开浏览器
      cors: true, // 允许跨域
      hmr: true,
      proxy: {},
    },
  };
});
